import { ref } from 'vue'
import { followService } from '@/api/consult'
import type { FollowType, Doctor } from '@/types/consult'
export const useFollow = (type: FollowType) => {
  // 关注逻辑
  const loading = ref(false)
  // {a, b} 类型，传值得时候 {a, b, c} 也可以，这是类型兼容：多的可以给少的
  const follow = async (obj: { id: string; likeFlag: 0 | 1 }) => {
    // 防止重复点击
    loading.value = true
    try {
      await followService(obj.id, type)
      // 说明：关注接口后台可能没有实现，存储关注状态
      obj.likeFlag = obj.likeFlag === 1 ? 0 : 1
    } finally {
      // 无论 try / catch 结果如何都会执行的代码块
      loading.value = false
    }
  }
  return {
    loading,
    follow,
  }
}
